//
//  showStudentsInfoSpecify.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/27.
//  Copyright © 2020 mqd. All rights reserved.
//
#include "list.hpp"
#include "Student.hpp"

void showStudentsInfoSpecify();
void findByName();
void findById();

void showStudentsInfoSpecify(){
    while(1){
        printf("======================\n");
        printf("|  指定学生信息         \n");
        printf("| 0. 退出          \n");
        printf("| 1. 查找姓名       \n");
        printf("| 2. 查找学号       \n");
        printf("======================\n");
        printf("请输入上面的标号: ");
        char c;
        std::cin>>c;
        for(int i=0;i<3;i++) printf("\n");
        if ( c=='1' ) findByName();
        if ( c=='2' ) findById();
        if ( c=='0' ) break;
    }
}

void findByName(){
    while(1){
        printf("请输入要查找的姓名:");
        std::string s;
        std::cin>>s;
        std::cout<<s<<" "<<s.size()<<std::endl;
        Student* stu= allStudents.findByName(s);
        if (stu) stu->print();
        else printf("未找到此人\n");
        printf("==========================\n");
        printf("   1.继续查找     0.退出\n");
        printf("==========================\n");
        char c;
        std::cin>>c;
        if (c=='0') break;
    }
}

void findById(){
    while(1){
        printf("请输入要查找的学号:");
        int id;
        std::cin>>id;
        Student* stu= allStudents.findById(id);
        if (stu) stu->print();
        else printf("该学号不存在\n");
        printf("==========================\n");
        printf("   1.继续查找     0.退出\n");
        printf("==========================\n");
        char c;
        std::cin>>c;
        if (c=='0') break;
    }
}
